<template>
    <div>
        <!-- 头部 -->
        <myheader/>
        <button @click="permissions">个人权限</button>

<div class='udlite-container parmtners'>
        <van-cell-group align='center'>
            <van-uploader :after-read="afterRead" />
        </van-cell-group>

        <van-cell-group v-if="photos" align='center'>
            <van-image round width='10rem' height='10rem' :src="photos" />
        </van-cell-group>
</div>

        <van-cell-group v-if="photos" align='center'>
            <table border="1px" cellspacing=0px>
                <tr>
                    <td>已关注课程题目</td>
                </tr>
                <tr v-for="(i,p) in course_name" :key=p>
                    <td>{{i.course_name}}</td>
                </tr>
            </table>
        </van-cell-group><br>


        <!-- 尾部 -->
        <mytail/>
    </div>

</template>

<script>
import myheader from './myheader.vue'
import mytail from './mytail.vue'
export default {
    data(){
        return{
            photos:localStorage.getItem('photos',null),
            course_name:[],
            
        }
    },
    //注册组件标签
    components:{
        // 头部
        'myheader':myheader,
        // 尾部
        'mytail':mytail,
    },
    mounted(){
        this.buycourse()
    },
    methods:{
        // 文件上传
        afterRead:function(file){
            // 定义参数
            let data=new FormData()
            data.append('file',file.file)

            let token=localStorage.getItem('token')
            data.append('token',token)
            // 创建实例
            const axiosInstance=this.axios.create({withCredentials:false})

            axiosInstance({method:'POST',url:'http://localhost:8000/upload/',data:data}).then(res=>{
                console.log(res)
                if(res.data.code==200){
                    localStorage.setItem('photos',res.data.src)
                    this.photos=res.data.src
                    this.$router.go(0)
                }
            })
        },
        permissions(){
            let token=localStorage.getItem('token')
            window.location.replace('http://localhost:8000/getuseraccess/?token='+token)
        },
        // 获取购买的课程
        buycourse(){
            let uid=localStorage.getItem('uid')
            let parm=new FormData()
            parm.append('uid',uid)
            this.axios.post('http://localhost:8000/buycourse/',parm).then((response)=>{
                console.log(response.data)
                this.course_name=response.data.data
            })
        }
    }
}
</script>

<style>

</style>